//
//  ThrottleButton.swift
//  ANOASTORE
//
//  Created by hudan on 2025/3/31.
//  Copyright © 2025 zwb. All rights reserved.
//

import UIKit

class ThrottleButton: UIButton {
    // 点击间隔时间
    var throttleInterval: TimeInterval = 0
    
    // 记录上次点击时间
    private var lastClickTime: TimeInterval = 0
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
        if throttleInterval <= 0 {
            super.sendAction(action, to: target, for: event)
            return
        }
        
        let currentTime = Date().timeIntervalSince1970
        if currentTime - lastClickTime > throttleInterval {
            lastClickTime = currentTime
            super.sendAction(action, to: target, for: event)
        }
    }
}
